package com.dayu.web.controller.store;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.store.domain.StoreFormula;
import com.dayu.store.service.IStoreFormulaService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 返利公式Controller
 * 
 * @author HK
 * @date 2021-07-02
 */
@RestController
@RequestMapping("/store/formula")
public class StoreFormulaController extends BaseController
{
    @Autowired
    private IStoreFormulaService storeFormulaService;

    /**
     * 查询返利公式列表
     */
    @PreAuthorize("@ss.hasPermi('store:formula:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreFormula storeFormula)
    {
        startPage();
        List<StoreFormula> list = storeFormulaService.selectStoreFormulaList(storeFormula);
        return getDataTable(list);
    }

    /**
     * 导出返利公式列表
     */
    @PreAuthorize("@ss.hasPermi('store:formula:export')")
    @Log(title = "返利公式", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StoreFormula storeFormula)
    {
        List<StoreFormula> list = storeFormulaService.selectStoreFormulaList(storeFormula);
        ExcelUtil<StoreFormula> util = new ExcelUtil<StoreFormula>(StoreFormula.class);
        return util.exportExcel(list, "formula");
    }

    /**
     * 获取返利公式详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:formula:query')")
    @GetMapping(value = "/{formulaId}")
    public AjaxResult getInfo(@PathVariable("formulaId") Long formulaId)
    {
        return AjaxResult.success(storeFormulaService.selectStoreFormulaById(formulaId));
    }

    /**
     * 新增返利公式
     */
    @PreAuthorize("@ss.hasPermi('store:formula:add')")
    @Log(title = "返利公式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreFormula storeFormula)
    {
        return toAjax(storeFormulaService.insertStoreFormula(storeFormula));
    }

    /**
     * 修改返利公式
     */
    @PreAuthorize("@ss.hasPermi('store:formula:edit')")
    @Log(title = "返利公式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreFormula storeFormula)
    {
        return toAjax(storeFormulaService.updateStoreFormula(storeFormula));
    }

    /**
     * 删除返利公式
     */
    @PreAuthorize("@ss.hasPermi('store:formula:remove')")
    @Log(title = "返利公式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{formulaIds}")
    public AjaxResult remove(@PathVariable Long[] formulaIds)
    {
        return toAjax(storeFormulaService.deleteStoreFormulaByIds(formulaIds));
    }
}
